
<!DOCTYPE html>

<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>pymatgen.command_line.gulp_caller &#8212; pymatgen 2020.7.3 documentation</title>
    <link rel="stylesheet" href="../../../_static/basic.css" type="text/css" />
    <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
    <script id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
    <script src="../../../_static/jquery.js"></script>
    <script src="../../../_static/underscore.js"></script>
    <script src="../../../_static/doctools.js"></script>
    <script src="../../../_static/language_data.js"></script>
    <script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <link rel="index" title="Index" href="../../../genindex.html" />
    <link rel="search" title="Search" href="../../../search.html" />
 
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-33990148-1']);
  _gaq.push(['_trackPageview']);
</script>

  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../index.html">pymatgen 2020.7.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../pymatgen.html" accesskey="U">pymatgen</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">pymatgen.command_line.gulp_caller</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
          <div class="body" role="main">
            
  <h1>Source code for pymatgen.command_line.gulp_caller</h1><div class="highlight"><pre>
<span></span><span class="c1"># coding: utf-8</span>
<span class="c1"># Copyright (c) Pymatgen Development Team.</span>
<span class="c1"># Distributed under the terms of the MIT License.</span>


<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">Interface with command line GULP.</span>
<span class="sd">http://projects.ivec.org</span>
<span class="sd">WARNING: you need to have GULP installed on your system.</span>
<span class="sd">&quot;&quot;&quot;</span>

<span class="n">__author__</span> <span class="o">=</span> <span class="s2">&quot;Bharat Medasani, Wenhao Sun&quot;</span>
<span class="n">__copyright__</span> <span class="o">=</span> <span class="s2">&quot;Copyright 2013, The Materials Project&quot;</span>
<span class="n">__version__</span> <span class="o">=</span> <span class="s2">&quot;1.0&quot;</span>
<span class="n">__maintainer__</span> <span class="o">=</span> <span class="s2">&quot;Bharat Medasani&quot;</span>
<span class="n">__email__</span> <span class="o">=</span> <span class="s2">&quot;bkmedasani@lbl.gov,wenhao@mit.edu&quot;</span>
<span class="n">__status__</span> <span class="o">=</span> <span class="s2">&quot;Production&quot;</span>
<span class="n">__date__</span> <span class="o">=</span> <span class="s2">&quot;$Jun 22, 2013M$&quot;</span>

<span class="kn">import</span> <span class="nn">subprocess</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">re</span>

<span class="kn">from</span> <span class="nn">pymatgen.core.periodic_table</span> <span class="kn">import</span> <span class="n">Element</span>
<span class="kn">from</span> <span class="nn">pymatgen.core.lattice</span> <span class="kn">import</span> <span class="n">Lattice</span>
<span class="kn">from</span> <span class="nn">pymatgen.core.structure</span> <span class="kn">import</span> <span class="n">Structure</span>
<span class="kn">from</span> <span class="nn">pymatgen.symmetry.analyzer</span> <span class="kn">import</span> <span class="n">SpacegroupAnalyzer</span>
<span class="kn">from</span> <span class="nn">pymatgen.analysis.bond_valence</span> <span class="kn">import</span> <span class="n">BVAnalyzer</span>

<span class="kn">from</span> <span class="nn">monty.tempfile</span> <span class="kn">import</span> <span class="n">ScratchDir</span>

<span class="n">_anions</span> <span class="o">=</span> <span class="nb">set</span><span class="p">(</span><span class="nb">map</span><span class="p">(</span><span class="n">Element</span><span class="p">,</span> <span class="p">[</span><span class="s2">&quot;O&quot;</span><span class="p">,</span> <span class="s2">&quot;S&quot;</span><span class="p">,</span> <span class="s2">&quot;F&quot;</span><span class="p">,</span> <span class="s2">&quot;Cl&quot;</span><span class="p">,</span> <span class="s2">&quot;Br&quot;</span><span class="p">,</span> <span class="s2">&quot;N&quot;</span><span class="p">,</span> <span class="s2">&quot;P&quot;</span><span class="p">]))</span>
<span class="n">_cations</span> <span class="o">=</span> <span class="nb">set</span><span class="p">(</span><span class="nb">map</span><span class="p">(</span><span class="n">Element</span><span class="p">,</span> <span class="p">[</span>
    <span class="s2">&quot;Li&quot;</span><span class="p">,</span> <span class="s2">&quot;Na&quot;</span><span class="p">,</span> <span class="s2">&quot;K&quot;</span><span class="p">,</span>  <span class="c1"># alkali metals</span>
    <span class="s2">&quot;Be&quot;</span><span class="p">,</span> <span class="s2">&quot;Mg&quot;</span><span class="p">,</span> <span class="s2">&quot;Ca&quot;</span><span class="p">,</span>  <span class="c1"># alkaline metals</span>
    <span class="s2">&quot;Al&quot;</span><span class="p">,</span> <span class="s2">&quot;Sc&quot;</span><span class="p">,</span> <span class="s2">&quot;Ti&quot;</span><span class="p">,</span> <span class="s2">&quot;V&quot;</span><span class="p">,</span> <span class="s2">&quot;Cr&quot;</span><span class="p">,</span> <span class="s2">&quot;Mn&quot;</span><span class="p">,</span> <span class="s2">&quot;Fe&quot;</span><span class="p">,</span> <span class="s2">&quot;Co&quot;</span><span class="p">,</span> <span class="s2">&quot;Ni&quot;</span><span class="p">,</span> <span class="s2">&quot;Cu&quot;</span><span class="p">,</span> <span class="s2">&quot;Zn&quot;</span><span class="p">,</span> <span class="s2">&quot;Ge&quot;</span><span class="p">,</span> <span class="s2">&quot;As&quot;</span><span class="p">,</span>
    <span class="s2">&quot;Y&quot;</span><span class="p">,</span> <span class="s2">&quot;Zr&quot;</span><span class="p">,</span> <span class="s2">&quot;Nb&quot;</span><span class="p">,</span> <span class="s2">&quot;Mo&quot;</span><span class="p">,</span> <span class="s2">&quot;Tc&quot;</span><span class="p">,</span> <span class="s2">&quot;Ru&quot;</span><span class="p">,</span> <span class="s2">&quot;Rh&quot;</span><span class="p">,</span> <span class="s2">&quot;Pd&quot;</span><span class="p">,</span> <span class="s2">&quot;Ag&quot;</span><span class="p">,</span> <span class="s2">&quot;Cd&quot;</span><span class="p">,</span> <span class="s2">&quot;In&quot;</span><span class="p">,</span> <span class="s2">&quot;Sn&quot;</span><span class="p">,</span> <span class="s2">&quot;Sb&quot;</span><span class="p">,</span>
    <span class="s2">&quot;Hf&quot;</span><span class="p">,</span> <span class="s2">&quot;Ta&quot;</span><span class="p">,</span> <span class="s2">&quot;W&quot;</span><span class="p">,</span> <span class="s2">&quot;Re&quot;</span><span class="p">,</span> <span class="s2">&quot;Os&quot;</span><span class="p">,</span> <span class="s2">&quot;Ir&quot;</span><span class="p">,</span> <span class="s2">&quot;Pt&quot;</span><span class="p">,</span> <span class="s2">&quot;Au&quot;</span><span class="p">,</span> <span class="s2">&quot;Hg&quot;</span><span class="p">,</span> <span class="s2">&quot;Tl&quot;</span><span class="p">,</span> <span class="s2">&quot;Pb&quot;</span><span class="p">,</span> <span class="s2">&quot;Bi&quot;</span><span class="p">,</span>
    <span class="s2">&quot;La&quot;</span><span class="p">,</span> <span class="s2">&quot;Ce&quot;</span><span class="p">,</span> <span class="s2">&quot;Pr&quot;</span><span class="p">,</span> <span class="s2">&quot;Nd&quot;</span><span class="p">,</span> <span class="s2">&quot;Pm&quot;</span><span class="p">,</span> <span class="s2">&quot;Sm&quot;</span><span class="p">,</span> <span class="s2">&quot;Eu&quot;</span><span class="p">,</span> <span class="s2">&quot;Gd&quot;</span><span class="p">,</span> <span class="s2">&quot;Tb&quot;</span><span class="p">,</span> <span class="s2">&quot;Dy&quot;</span><span class="p">,</span> <span class="s2">&quot;Ho&quot;</span><span class="p">,</span> <span class="s2">&quot;Er&quot;</span><span class="p">,</span>
    <span class="s2">&quot;Tm&quot;</span><span class="p">,</span> <span class="s2">&quot;Yb&quot;</span><span class="p">,</span> <span class="s2">&quot;Lu&quot;</span>
<span class="p">]))</span>
<span class="n">_gulp_kw</span> <span class="o">=</span> <span class="p">{</span>
    <span class="c1"># Control of calculation type</span>
    <span class="s2">&quot;angle&quot;</span><span class="p">,</span> <span class="s2">&quot;bond&quot;</span><span class="p">,</span> <span class="s2">&quot;cosmo&quot;</span><span class="p">,</span> <span class="s2">&quot;cosmic&quot;</span><span class="p">,</span> <span class="s2">&quot;cost&quot;</span><span class="p">,</span> <span class="s2">&quot;defect&quot;</span><span class="p">,</span> <span class="s2">&quot;distance&quot;</span><span class="p">,</span>
    <span class="s2">&quot;eem&quot;</span><span class="p">,</span> <span class="s2">&quot;efg&quot;</span><span class="p">,</span> <span class="s2">&quot;fit&quot;</span><span class="p">,</span> <span class="s2">&quot;free_energy&quot;</span><span class="p">,</span> <span class="s2">&quot;gasteiger&quot;</span><span class="p">,</span> <span class="s2">&quot;genetic&quot;</span><span class="p">,</span>
    <span class="s2">&quot;gradients&quot;</span><span class="p">,</span> <span class="s2">&quot;md&quot;</span><span class="p">,</span> <span class="s2">&quot;montecarlo&quot;</span><span class="p">,</span> <span class="s2">&quot;noautobond&quot;</span><span class="p">,</span> <span class="s2">&quot;noenergy&quot;</span><span class="p">,</span> <span class="s2">&quot;optimise&quot;</span><span class="p">,</span>
    <span class="s2">&quot;pot&quot;</span><span class="p">,</span> <span class="s2">&quot;predict&quot;</span><span class="p">,</span> <span class="s2">&quot;preserve_Q&quot;</span><span class="p">,</span> <span class="s2">&quot;property&quot;</span><span class="p">,</span> <span class="s2">&quot;phonon&quot;</span><span class="p">,</span> <span class="s2">&quot;qeq&quot;</span><span class="p">,</span> <span class="s2">&quot;qbond&quot;</span><span class="p">,</span>
    <span class="s2">&quot;single&quot;</span><span class="p">,</span> <span class="s2">&quot;sm&quot;</span><span class="p">,</span> <span class="s2">&quot;static_first&quot;</span><span class="p">,</span> <span class="s2">&quot;torsion&quot;</span><span class="p">,</span> <span class="s2">&quot;transition_state&quot;</span><span class="p">,</span>
    <span class="c1"># Geometric variable specification</span>
    <span class="s2">&quot;breathe&quot;</span><span class="p">,</span> <span class="s2">&quot;bulk_noopt&quot;</span><span class="p">,</span> <span class="s2">&quot;cellonly&quot;</span><span class="p">,</span> <span class="s2">&quot;conp&quot;</span><span class="p">,</span> <span class="s2">&quot;conv&quot;</span><span class="p">,</span> <span class="s2">&quot;isotropic&quot;</span><span class="p">,</span>
    <span class="s2">&quot;orthorhombic&quot;</span><span class="p">,</span> <span class="s2">&quot;nobreathe&quot;</span><span class="p">,</span> <span class="s2">&quot;noflgs&quot;</span><span class="p">,</span> <span class="s2">&quot;shell&quot;</span><span class="p">,</span> <span class="s2">&quot;unfix&quot;</span><span class="p">,</span>
    <span class="c1"># Algorithm</span>
    <span class="s2">&quot;c6&quot;</span><span class="p">,</span> <span class="s2">&quot;dipole&quot;</span><span class="p">,</span> <span class="s2">&quot;fbfgs&quot;</span><span class="p">,</span> <span class="s2">&quot;fix_molecule&quot;</span><span class="p">,</span> <span class="s2">&quot;full&quot;</span><span class="p">,</span> <span class="s2">&quot;hill&quot;</span><span class="p">,</span> <span class="s2">&quot;kfull&quot;</span><span class="p">,</span>
    <span class="s2">&quot;marvinSE&quot;</span><span class="p">,</span> <span class="s2">&quot;madelung&quot;</span><span class="p">,</span> <span class="s2">&quot;minimum_image&quot;</span><span class="p">,</span> <span class="s2">&quot;molecule&quot;</span><span class="p">,</span> <span class="s2">&quot;molmec&quot;</span><span class="p">,</span> <span class="s2">&quot;molq&quot;</span><span class="p">,</span>
    <span class="s2">&quot;newda&quot;</span><span class="p">,</span> <span class="s2">&quot;noanisotropic_2b&quot;</span><span class="p">,</span> <span class="s2">&quot;nod2sym&quot;</span><span class="p">,</span> <span class="s2">&quot;nodsymmetry&quot;</span><span class="p">,</span>
    <span class="s2">&quot;noelectrostatics&quot;</span><span class="p">,</span> <span class="s2">&quot;noexclude&quot;</span><span class="p">,</span> <span class="s2">&quot;nofcentral&quot;</span><span class="p">,</span> <span class="s2">&quot;nofirst_point&quot;</span><span class="p">,</span>
    <span class="s2">&quot;noksymmetry&quot;</span><span class="p">,</span> <span class="s2">&quot;nolist_md&quot;</span><span class="p">,</span> <span class="s2">&quot;nomcediff&quot;</span><span class="p">,</span> <span class="s2">&quot;nonanal&quot;</span><span class="p">,</span> <span class="s2">&quot;noquicksearch&quot;</span><span class="p">,</span>
    <span class="s2">&quot;noreal&quot;</span><span class="p">,</span> <span class="s2">&quot;norecip&quot;</span><span class="p">,</span> <span class="s2">&quot;norepulsive&quot;</span><span class="p">,</span> <span class="s2">&quot;nosasinitevery&quot;</span><span class="p">,</span> <span class="s2">&quot;nosderv&quot;</span><span class="p">,</span>
    <span class="s2">&quot;nozeropt&quot;</span><span class="p">,</span> <span class="s2">&quot;numerical&quot;</span><span class="p">,</span> <span class="s2">&quot;qiter&quot;</span><span class="p">,</span> <span class="s2">&quot;qok&quot;</span><span class="p">,</span> <span class="s2">&quot;spatial&quot;</span><span class="p">,</span> <span class="s2">&quot;storevectors&quot;</span><span class="p">,</span>
    <span class="s2">&quot;nomolecularinternalke&quot;</span><span class="p">,</span> <span class="s2">&quot;voight&quot;</span><span class="p">,</span> <span class="s2">&quot;zsisa&quot;</span><span class="p">,</span>
    <span class="c1"># Optimisation method</span>
    <span class="s2">&quot;conjugate&quot;</span><span class="p">,</span> <span class="s2">&quot;dfp&quot;</span><span class="p">,</span> <span class="s2">&quot;lbfgs&quot;</span><span class="p">,</span> <span class="s2">&quot;numdiag&quot;</span><span class="p">,</span> <span class="s2">&quot;positive&quot;</span><span class="p">,</span> <span class="s2">&quot;rfo&quot;</span><span class="p">,</span> <span class="s2">&quot;unit&quot;</span><span class="p">,</span>
    <span class="c1"># Output control</span>
    <span class="s2">&quot;average&quot;</span><span class="p">,</span> <span class="s2">&quot;broaden_dos&quot;</span><span class="p">,</span> <span class="s2">&quot;cartesian&quot;</span><span class="p">,</span> <span class="s2">&quot;compare&quot;</span><span class="p">,</span> <span class="s2">&quot;conserved&quot;</span><span class="p">,</span>
    <span class="s2">&quot;dcharge&quot;</span><span class="p">,</span> <span class="s2">&quot;dynamical_matrix&quot;</span><span class="p">,</span>
    <span class="s2">&quot;eigenvectors&quot;</span><span class="p">,</span> <span class="s2">&quot;global&quot;</span><span class="p">,</span> <span class="s2">&quot;hessian&quot;</span><span class="p">,</span> <span class="s2">&quot;hexagonal&quot;</span><span class="p">,</span> <span class="s2">&quot;intensity&quot;</span><span class="p">,</span> <span class="s2">&quot;linmin&quot;</span><span class="p">,</span>
    <span class="s2">&quot;meanke&quot;</span><span class="p">,</span> <span class="s2">&quot;nodensity_out&quot;</span><span class="p">,</span> <span class="s2">&quot;nodpsym&quot;</span><span class="p">,</span> <span class="s2">&quot;nofirst_point&quot;</span><span class="p">,</span> <span class="s2">&quot;nofrequency&quot;</span><span class="p">,</span>
    <span class="s2">&quot;nokpoints&quot;</span><span class="p">,</span> <span class="s2">&quot;operators&quot;</span><span class="p">,</span> <span class="s2">&quot;outcon&quot;</span><span class="p">,</span> <span class="s2">&quot;prt_eam&quot;</span><span class="p">,</span> <span class="s2">&quot;prt_two&quot;</span><span class="p">,</span>
    <span class="s2">&quot;prt_regi_before&quot;</span><span class="p">,</span> <span class="s2">&quot;qsas&quot;</span><span class="p">,</span> <span class="s2">&quot;restore&quot;</span><span class="p">,</span> <span class="s2">&quot;save&quot;</span><span class="p">,</span> <span class="s2">&quot;terse&quot;</span><span class="p">,</span>
    <span class="c1"># Structure control</span>
    <span class="s2">&quot;full&quot;</span><span class="p">,</span> <span class="s2">&quot;hexagonal&quot;</span><span class="p">,</span> <span class="s2">&quot;lower_symmetry&quot;</span><span class="p">,</span> <span class="s2">&quot;nosymmetry&quot;</span><span class="p">,</span>
    <span class="c1"># PDF control</span>
    <span class="s2">&quot;PDF&quot;</span><span class="p">,</span> <span class="s2">&quot;PDFcut&quot;</span><span class="p">,</span> <span class="s2">&quot;PDFbelow&quot;</span><span class="p">,</span> <span class="s2">&quot;PDFkeep&quot;</span><span class="p">,</span> <span class="s2">&quot;coreinfo&quot;</span><span class="p">,</span> <span class="s2">&quot;nowidth&quot;</span><span class="p">,</span> <span class="s2">&quot;nopartial&quot;</span><span class="p">,</span>
    <span class="c1"># Miscellaneous</span>
    <span class="s2">&quot;nomodcoord&quot;</span><span class="p">,</span> <span class="s2">&quot;oldunits&quot;</span><span class="p">,</span> <span class="s2">&quot;zero_potential&quot;</span>
<span class="p">}</span>


<div class="viewcode-block" id="GulpIO"><a class="viewcode-back" href="../../../pymatgen.command_line.gulp_caller.html#pymatgen.command_line.gulp_caller.GulpIO">[docs]</a><span class="k">class</span> <span class="nc">GulpIO</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    To generate GULP input and process output</span>
<span class="sd">    &quot;&quot;&quot;</span>

<div class="viewcode-block" id="GulpIO.keyword_line"><a class="viewcode-back" href="../../../pymatgen.command_line.gulp_caller.html#pymatgen.command_line.gulp_caller.GulpIO.keyword_line">[docs]</a>    <span class="k">def</span> <span class="nf">keyword_line</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">):</span>
        <span class="sa">r</span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Checks if the input args are proper gulp keywords and</span>
<span class="sd">        generates the 1st line of gulp input. Full keywords are expected.</span>

<span class="sd">        Args:</span>
<span class="sd">            \\*args: 1st line keywords</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># if len(list(filter(lambda x: x in _gulp_kw, args))) != len(args):</span>
        <span class="c1">#    raise GulpError(&quot;Wrong keywords given&quot;)</span>
        <span class="n">gin</span> <span class="o">=</span> <span class="s2">&quot; &quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">args</span><span class="p">)</span>
        <span class="n">gin</span> <span class="o">+=</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span>
        <span class="k">return</span> <span class="n">gin</span></div>

<div class="viewcode-block" id="GulpIO.structure_lines"><a class="viewcode-back" href="../../../pymatgen.command_line.gulp_caller.html#pymatgen.command_line.gulp_caller.GulpIO.structure_lines">[docs]</a>    <span class="k">def</span> <span class="nf">structure_lines</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">structure</span><span class="p">,</span> <span class="n">cell_flg</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">frac_flg</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
                        <span class="n">anion_shell_flg</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">cation_shell_flg</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                        <span class="n">symm_flg</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Generates GULP input string corresponding to pymatgen structure.</span>

<span class="sd">        Args:</span>
<span class="sd">            structure: pymatgen Structure object</span>
<span class="sd">            cell_flg (default = True): Option to use lattice parameters.</span>
<span class="sd">            fractional_flg (default = True): If True, fractional coordinates</span>
<span class="sd">                are used. Else, cartesian coodinates in Angstroms are used.</span>
<span class="sd">                ******</span>
<span class="sd">                GULP convention is to use fractional coordinates for periodic</span>
<span class="sd">                structures and cartesian coordinates for non-periodic</span>
<span class="sd">                structures.</span>
<span class="sd">                ******</span>
<span class="sd">            anion_shell_flg (default = True): If True, anions are considered</span>
<span class="sd">                polarizable.</span>
<span class="sd">            cation_shell_flg (default = False): If True, cations are</span>
<span class="sd">                considered polarizable.</span>
<span class="sd">            symm_flg (default = True): If True, symmetry information is also</span>
<span class="sd">                written.</span>

<span class="sd">        Returns:</span>
<span class="sd">            string containing structure for GULP input</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">gin</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
        <span class="k">if</span> <span class="n">cell_flg</span><span class="p">:</span>
            <span class="n">gin</span> <span class="o">+=</span> <span class="s2">&quot;cell</span><span class="se">\n</span><span class="s2">&quot;</span>
            <span class="n">l</span> <span class="o">=</span> <span class="n">structure</span><span class="o">.</span><span class="n">lattice</span>
            <span class="n">lat_str</span> <span class="o">=</span> <span class="s2">&quot;</span><span class="si">{0:6f}</span><span class="s2"> </span><span class="si">{1:6f}</span><span class="s2"> </span><span class="si">{2:6f}</span><span class="s2"> </span><span class="si">{3:6f}</span><span class="s2"> </span><span class="si">{4:6f}</span><span class="s2"> </span><span class="si">{5:6f}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                <span class="n">l</span><span class="o">.</span><span class="n">a</span><span class="p">,</span> <span class="n">l</span><span class="o">.</span><span class="n">b</span><span class="p">,</span> <span class="n">l</span><span class="o">.</span><span class="n">c</span><span class="p">,</span> <span class="n">l</span><span class="o">.</span><span class="n">alpha</span><span class="p">,</span> <span class="n">l</span><span class="o">.</span><span class="n">beta</span><span class="p">,</span> <span class="n">l</span><span class="o">.</span><span class="n">gamma</span>
            <span class="p">)</span>
            <span class="n">gin</span> <span class="o">+=</span> <span class="n">lat_str</span> <span class="o">+</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span>

        <span class="k">if</span> <span class="n">frac_flg</span><span class="p">:</span>
            <span class="n">gin</span> <span class="o">+=</span> <span class="s2">&quot;frac</span><span class="se">\n</span><span class="s2">&quot;</span>
            <span class="n">coord_attr</span> <span class="o">=</span> <span class="s2">&quot;frac_coords&quot;</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">gin</span> <span class="o">+=</span> <span class="s2">&quot;cart</span><span class="se">\n</span><span class="s2">&quot;</span>
            <span class="n">coord_attr</span> <span class="o">=</span> <span class="s2">&quot;coords&quot;</span>
        <span class="k">for</span> <span class="n">site</span> <span class="ow">in</span> <span class="n">structure</span><span class="o">.</span><span class="n">sites</span><span class="p">:</span>
            <span class="n">coord</span> <span class="o">=</span> <span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">site</span><span class="p">,</span> <span class="n">coord_attr</span><span class="p">)]</span>
            <span class="n">specie</span> <span class="o">=</span> <span class="n">site</span><span class="o">.</span><span class="n">specie</span>
            <span class="n">core_site_desc</span> <span class="o">=</span> <span class="n">specie</span><span class="o">.</span><span class="n">symbol</span> <span class="o">+</span> <span class="s2">&quot; core &quot;</span> <span class="o">+</span> <span class="s2">&quot; &quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">coord</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span>
            <span class="n">gin</span> <span class="o">+=</span> <span class="n">core_site_desc</span>
            <span class="k">if</span> <span class="p">((</span><span class="n">specie</span> <span class="ow">in</span> <span class="n">_anions</span> <span class="ow">and</span> <span class="n">anion_shell_flg</span><span class="p">)</span> <span class="ow">or</span>
                    <span class="p">(</span><span class="n">specie</span> <span class="ow">in</span> <span class="n">_cations</span> <span class="ow">and</span> <span class="n">cation_shell_flg</span><span class="p">)):</span>
                <span class="n">shel_site_desc</span> <span class="o">=</span> <span class="n">specie</span><span class="o">.</span><span class="n">symbol</span> <span class="o">+</span> <span class="s2">&quot; shel &quot;</span> <span class="o">+</span> <span class="s2">&quot; &quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span>
                    <span class="n">coord</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span>
                <span class="n">gin</span> <span class="o">+=</span> <span class="n">shel_site_desc</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">pass</span>

        <span class="k">if</span> <span class="n">symm_flg</span><span class="p">:</span>
            <span class="n">gin</span> <span class="o">+=</span> <span class="s2">&quot;space</span><span class="se">\n</span><span class="s2">&quot;</span>
            <span class="n">gin</span> <span class="o">+=</span> <span class="nb">str</span><span class="p">(</span><span class="n">SpacegroupAnalyzer</span><span class="p">(</span><span class="n">structure</span><span class="p">)</span><span class="o">.</span><span class="n">get_space_group_number</span><span class="p">())</span> <span class="o">+</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span>
        <span class="k">return</span> <span class="n">gin</span></div>

<div class="viewcode-block" id="GulpIO.specie_potential_lines"><a class="viewcode-back" href="../../../pymatgen.command_line.gulp_caller.html#pymatgen.command_line.gulp_caller.GulpIO.specie_potential_lines">[docs]</a>    <span class="k">def</span> <span class="nf">specie_potential_lines</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">structure</span><span class="p">,</span> <span class="n">potential</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sa">r</span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Generates GULP input specie and potential string for pymatgen</span>
<span class="sd">        structure.</span>

<span class="sd">        Args:</span>
<span class="sd">            structure: pymatgen.core.structure.Structure object</span>
<span class="sd">            potential: String specifying the type of potential used</span>
<span class="sd">            \\*\\*kwargs: Additional parameters related to potential. For</span>
<span class="sd">                potential == &quot;buckingham&quot;,</span>
<span class="sd">                anion_shell_flg (default = False):</span>
<span class="sd">                If True, anions are considered polarizable.</span>
<span class="sd">                anion_core_chrg=float</span>
<span class="sd">                anion_shell_chrg=float</span>
<span class="sd">                cation_shell_flg (default = False):</span>
<span class="sd">                If True, cations are considered polarizable.</span>
<span class="sd">                cation_core_chrg=float</span>
<span class="sd">                cation_shell_chrg=float</span>

<span class="sd">        Returns:</span>
<span class="sd">            string containing specie and potential specification for gulp</span>
<span class="sd">            input.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="s2">&quot;gulp_specie_potential not yet implemented.&quot;</span>
                                  <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">Use library_line instead&quot;</span><span class="p">)</span></div>

<div class="viewcode-block" id="GulpIO.library_line"><a class="viewcode-back" href="../../../pymatgen.command_line.gulp_caller.html#pymatgen.command_line.gulp_caller.GulpIO.library_line">[docs]</a>    <span class="k">def</span> <span class="nf">library_line</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">file_name</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Specifies GULP library file to read species and potential parameters.</span>
<span class="sd">        If using library don&#39;t specify species and potential</span>
<span class="sd">        in the input file and vice versa. Make sure the elements of</span>
<span class="sd">        structure are in the library file.</span>

<span class="sd">        Args:</span>
<span class="sd">            file_name: Name of GULP library file</span>

<span class="sd">        Returns:</span>
<span class="sd">            GULP input string specifying library option</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">gulplib_set</span> <span class="o">=</span> <span class="s1">&#39;GULP_LIB&#39;</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="o">.</span><span class="n">keys</span><span class="p">()</span>

        <span class="k">def</span> <span class="nf">readable</span><span class="p">(</span><span class="n">f</span><span class="p">):</span>
            <span class="k">return</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">isfile</span><span class="p">(</span><span class="n">f</span><span class="p">)</span> <span class="ow">and</span> <span class="n">os</span><span class="o">.</span><span class="n">access</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">os</span><span class="o">.</span><span class="n">R_OK</span><span class="p">)</span>

        <span class="n">gin</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
        <span class="n">dirpath</span><span class="p">,</span> <span class="n">fname</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="n">file_name</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">dirpath</span> <span class="ow">and</span> <span class="n">readable</span><span class="p">(</span><span class="n">file_name</span><span class="p">):</span>  <span class="c1"># Full path specified</span>
            <span class="n">gin</span> <span class="o">=</span> <span class="s1">&#39;library &#39;</span> <span class="o">+</span> <span class="n">file_name</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">fpath</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">getcwd</span><span class="p">(),</span> <span class="n">file_name</span><span class="p">)</span>  <span class="c1"># Check current dir</span>
            <span class="k">if</span> <span class="n">readable</span><span class="p">(</span><span class="n">fpath</span><span class="p">):</span>
                <span class="n">gin</span> <span class="o">=</span> <span class="s1">&#39;library &#39;</span> <span class="o">+</span> <span class="n">fpath</span>
            <span class="k">elif</span> <span class="n">gulplib_set</span><span class="p">:</span>  <span class="c1"># Check the GULP_LIB path</span>
                <span class="n">fpath</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s1">&#39;GULP_LIB&#39;</span><span class="p">],</span> <span class="n">file_name</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">readable</span><span class="p">(</span><span class="n">fpath</span><span class="p">):</span>
                    <span class="n">gin</span> <span class="o">=</span> <span class="s1">&#39;library &#39;</span> <span class="o">+</span> <span class="n">file_name</span>
        <span class="k">if</span> <span class="n">gin</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">gin</span> <span class="o">+</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="n">GulpError</span><span class="p">(</span><span class="s1">&#39;GULP Library not found&#39;</span><span class="p">)</span></div>

<div class="viewcode-block" id="GulpIO.buckingham_input"><a class="viewcode-back" href="../../../pymatgen.command_line.gulp_caller.html#pymatgen.command_line.gulp_caller.GulpIO.buckingham_input">[docs]</a>    <span class="k">def</span> <span class="nf">buckingham_input</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">structure</span><span class="p">,</span> <span class="n">keywords</span><span class="p">,</span> <span class="n">library</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                         <span class="n">uc</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">valence_dict</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Gets a GULP input for an oxide structure and buckingham potential</span>
<span class="sd">        from library.</span>

<span class="sd">        Args:</span>
<span class="sd">            structure: pymatgen.core.structure.Structure</span>
<span class="sd">            keywords: GULP first line keywords.</span>
<span class="sd">            library (Default=None): File containing the species and potential.</span>
<span class="sd">            uc (Default=True): Unit Cell Flag.</span>
<span class="sd">            valence_dict: {El: valence}</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">gin</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">keyword_line</span><span class="p">(</span><span class="o">*</span><span class="n">keywords</span><span class="p">)</span>
        <span class="n">gin</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">structure_lines</span><span class="p">(</span><span class="n">structure</span><span class="p">,</span> <span class="n">symm_flg</span><span class="o">=</span><span class="ow">not</span> <span class="n">uc</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">library</span><span class="p">:</span>
            <span class="n">gin</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">buckingham_potential</span><span class="p">(</span><span class="n">structure</span><span class="p">,</span> <span class="n">valence_dict</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">gin</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">library_line</span><span class="p">(</span><span class="n">library</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">gin</span></div>

<div class="viewcode-block" id="GulpIO.buckingham_potential"><a class="viewcode-back" href="../../../pymatgen.command_line.gulp_caller.html#pymatgen.command_line.gulp_caller.GulpIO.buckingham_potential">[docs]</a>    <span class="k">def</span> <span class="nf">buckingham_potential</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">structure</span><span class="p">,</span> <span class="n">val_dict</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Generate species, buckingham, and spring options for an oxide structure</span>
<span class="sd">        using the parameters in default libraries.</span>

<span class="sd">        Ref:</span>
<span class="sd">            1. G.V. Lewis and C.R.A. Catlow, J. Phys. C: Solid State Phys.,</span>
<span class="sd">               18, 1149-1161 (1985)</span>
<span class="sd">            2. T.S.Bush, J.D.Gale, C.R.A.Catlow and P.D. Battle,</span>
<span class="sd">               J. Mater Chem., 4, 831-837 (1994)</span>

<span class="sd">        Args:</span>
<span class="sd">            structure: pymatgen.core.structure.Structure</span>
<span class="sd">            val_dict (Needed if structure is not charge neutral): {El:valence}</span>
<span class="sd">                dict, where El is element.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">val_dict</span><span class="p">:</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="c1"># If structure is oxidation state decorated, use that first.</span>
                <span class="n">el</span> <span class="o">=</span> <span class="p">[</span><span class="n">site</span><span class="o">.</span><span class="n">specie</span><span class="o">.</span><span class="n">symbol</span> <span class="k">for</span> <span class="n">site</span> <span class="ow">in</span> <span class="n">structure</span><span class="p">]</span>
                <span class="n">valences</span> <span class="o">=</span> <span class="p">[</span><span class="n">site</span><span class="o">.</span><span class="n">specie</span><span class="o">.</span><span class="n">oxi_state</span> <span class="k">for</span> <span class="n">site</span> <span class="ow">in</span> <span class="n">structure</span><span class="p">]</span>
                <span class="n">val_dict</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span><span class="nb">zip</span><span class="p">(</span><span class="n">el</span><span class="p">,</span> <span class="n">valences</span><span class="p">))</span>
            <span class="k">except</span> <span class="ne">AttributeError</span><span class="p">:</span>
                <span class="n">bv</span> <span class="o">=</span> <span class="n">BVAnalyzer</span><span class="p">()</span>
                <span class="n">el</span> <span class="o">=</span> <span class="p">[</span><span class="n">site</span><span class="o">.</span><span class="n">specie</span><span class="o">.</span><span class="n">symbol</span> <span class="k">for</span> <span class="n">site</span> <span class="ow">in</span> <span class="n">structure</span><span class="p">]</span>
                <span class="n">valences</span> <span class="o">=</span> <span class="n">bv</span><span class="o">.</span><span class="n">get_valences</span><span class="p">(</span><span class="n">structure</span><span class="p">)</span>
                <span class="n">val_dict</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span><span class="nb">zip</span><span class="p">(</span><span class="n">el</span><span class="p">,</span> <span class="n">valences</span><span class="p">))</span>

        <span class="c1"># Try bush library first</span>
        <span class="n">bpb</span> <span class="o">=</span> <span class="n">BuckinghamPotential</span><span class="p">(</span><span class="s1">&#39;bush&#39;</span><span class="p">)</span>
        <span class="n">bpl</span> <span class="o">=</span> <span class="n">BuckinghamPotential</span><span class="p">(</span><span class="s1">&#39;lewis&#39;</span><span class="p">)</span>
        <span class="n">gin</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
        <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">val_dict</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
            <span class="n">use_bush</span> <span class="o">=</span> <span class="kc">True</span>
            <span class="n">el</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">sub</span><span class="p">(</span><span class="sa">r</span><span class="s1">&#39;[1-9,+,\-]&#39;</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="n">key</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">el</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">bpb</span><span class="o">.</span><span class="n">species_dict</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
                <span class="n">use_bush</span> <span class="o">=</span> <span class="kc">False</span>
            <span class="k">elif</span> <span class="n">val_dict</span><span class="p">[</span><span class="n">key</span><span class="p">]</span> <span class="o">!=</span> <span class="n">bpb</span><span class="o">.</span><span class="n">species_dict</span><span class="p">[</span><span class="n">el</span><span class="p">][</span><span class="s1">&#39;oxi&#39;</span><span class="p">]:</span>
                <span class="n">use_bush</span> <span class="o">=</span> <span class="kc">False</span>
            <span class="k">if</span> <span class="n">use_bush</span><span class="p">:</span>
                <span class="n">gin</span> <span class="o">+=</span> <span class="s2">&quot;species </span><span class="se">\n</span><span class="s2">&quot;</span>
                <span class="n">gin</span> <span class="o">+=</span> <span class="n">bpb</span><span class="o">.</span><span class="n">species_dict</span><span class="p">[</span><span class="n">el</span><span class="p">][</span><span class="s1">&#39;inp_str&#39;</span><span class="p">]</span>
                <span class="n">gin</span> <span class="o">+=</span> <span class="s2">&quot;buckingham </span><span class="se">\n</span><span class="s2">&quot;</span>
                <span class="n">gin</span> <span class="o">+=</span> <span class="n">bpb</span><span class="o">.</span><span class="n">pot_dict</span><span class="p">[</span><span class="n">el</span><span class="p">]</span>
                <span class="n">gin</span> <span class="o">+=</span> <span class="s2">&quot;spring </span><span class="se">\n</span><span class="s2">&quot;</span>
                <span class="n">gin</span> <span class="o">+=</span> <span class="n">bpb</span><span class="o">.</span><span class="n">spring_dict</span><span class="p">[</span><span class="n">el</span><span class="p">]</span>
                <span class="k">continue</span>

            <span class="c1"># Try lewis library next if element is not in bush</span>
            <span class="c1"># use_lewis = True</span>
            <span class="k">if</span> <span class="n">el</span> <span class="o">!=</span> <span class="s2">&quot;O&quot;</span><span class="p">:</span>  <span class="c1"># For metals the key is &quot;Metal_OxiState+&quot;</span>
                <span class="n">k</span> <span class="o">=</span> <span class="n">el</span> <span class="o">+</span> <span class="s1">&#39;_&#39;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">val_dict</span><span class="p">[</span><span class="n">key</span><span class="p">]))</span> <span class="o">+</span> <span class="s1">&#39;+&#39;</span>
                <span class="k">if</span> <span class="n">k</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">bpl</span><span class="o">.</span><span class="n">species_dict</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
                    <span class="c1"># use_lewis = False</span>
                    <span class="k">raise</span> <span class="n">GulpError</span><span class="p">(</span><span class="s2">&quot;Element </span><span class="si">{}</span><span class="s2"> not in library&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">k</span><span class="p">))</span>
                <span class="n">gin</span> <span class="o">+=</span> <span class="s2">&quot;species</span><span class="se">\n</span><span class="s2">&quot;</span>
                <span class="n">gin</span> <span class="o">+=</span> <span class="n">bpl</span><span class="o">.</span><span class="n">species_dict</span><span class="p">[</span><span class="n">k</span><span class="p">]</span>
                <span class="n">gin</span> <span class="o">+=</span> <span class="s2">&quot;buckingham</span><span class="se">\n</span><span class="s2">&quot;</span>
                <span class="n">gin</span> <span class="o">+=</span> <span class="n">bpl</span><span class="o">.</span><span class="n">pot_dict</span><span class="p">[</span><span class="n">k</span><span class="p">]</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">gin</span> <span class="o">+=</span> <span class="s2">&quot;species</span><span class="se">\n</span><span class="s2">&quot;</span>
                <span class="n">k</span> <span class="o">=</span> <span class="s2">&quot;O_core&quot;</span>
                <span class="n">gin</span> <span class="o">+=</span> <span class="n">bpl</span><span class="o">.</span><span class="n">species_dict</span><span class="p">[</span><span class="n">k</span><span class="p">]</span>
                <span class="n">k</span> <span class="o">=</span> <span class="s2">&quot;O_shel&quot;</span>
                <span class="n">gin</span> <span class="o">+=</span> <span class="n">bpl</span><span class="o">.</span><span class="n">species_dict</span><span class="p">[</span><span class="n">k</span><span class="p">]</span>
                <span class="n">gin</span> <span class="o">+=</span> <span class="s2">&quot;buckingham</span><span class="se">\n</span><span class="s2">&quot;</span>
                <span class="n">gin</span> <span class="o">+=</span> <span class="n">bpl</span><span class="o">.</span><span class="n">pot_dict</span><span class="p">[</span><span class="n">key</span><span class="p">]</span>
                <span class="n">gin</span> <span class="o">+=</span> <span class="s1">&#39;spring</span><span class="se">\n</span><span class="s1">&#39;</span>
                <span class="n">gin</span> <span class="o">+=</span> <span class="n">bpl</span><span class="o">.</span><span class="n">spring_dict</span><span class="p">[</span><span class="n">key</span><span class="p">]</span>
        <span class="k">return</span> <span class="n">gin</span></div>

<div class="viewcode-block" id="GulpIO.tersoff_input"><a class="viewcode-back" href="../../../pymatgen.command_line.gulp_caller.html#pymatgen.command_line.gulp_caller.GulpIO.tersoff_input">[docs]</a>    <span class="k">def</span> <span class="nf">tersoff_input</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">structure</span><span class="p">,</span> <span class="n">periodic</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">uc</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="o">*</span><span class="n">keywords</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Gets a GULP input with Tersoff potential for an oxide structure</span>

<span class="sd">        Args:</span>
<span class="sd">            structure: pymatgen.core.structure.Structure</span>
<span class="sd">            periodic (Default=False): Flag denoting whether periodic</span>
<span class="sd">                boundary conditions are used</span>
<span class="sd">            library (Default=None): File containing the species and potential.</span>
<span class="sd">            uc (Default=True): Unit Cell Flag.</span>
<span class="sd">            keywords: GULP first line keywords.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># gin=&quot;static noelectrostatics \n &quot;</span>
        <span class="n">gin</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">keyword_line</span><span class="p">(</span><span class="o">*</span><span class="n">keywords</span><span class="p">)</span>
        <span class="n">gin</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">structure_lines</span><span class="p">(</span>
            <span class="n">structure</span><span class="p">,</span> <span class="n">cell_flg</span><span class="o">=</span><span class="n">periodic</span><span class="p">,</span> <span class="n">frac_flg</span><span class="o">=</span><span class="n">periodic</span><span class="p">,</span>
            <span class="n">anion_shell_flg</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">cation_shell_flg</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">symm_flg</span><span class="o">=</span><span class="ow">not</span> <span class="n">uc</span>
        <span class="p">)</span>
        <span class="n">gin</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">tersoff_potential</span><span class="p">(</span><span class="n">structure</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">gin</span></div>

<div class="viewcode-block" id="GulpIO.tersoff_potential"><a class="viewcode-back" href="../../../pymatgen.command_line.gulp_caller.html#pymatgen.command_line.gulp_caller.GulpIO.tersoff_potential">[docs]</a>    <span class="k">def</span> <span class="nf">tersoff_potential</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">structure</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Generate the species, tersoff potential lines for an oxide structure</span>

<span class="sd">        Args:</span>
<span class="sd">            structure: pymatgen.core.structure.Structure</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">bv</span> <span class="o">=</span> <span class="n">BVAnalyzer</span><span class="p">()</span>
        <span class="n">el</span> <span class="o">=</span> <span class="p">[</span><span class="n">site</span><span class="o">.</span><span class="n">specie</span><span class="o">.</span><span class="n">symbol</span> <span class="k">for</span> <span class="n">site</span> <span class="ow">in</span> <span class="n">structure</span><span class="p">]</span>
        <span class="n">valences</span> <span class="o">=</span> <span class="n">bv</span><span class="o">.</span><span class="n">get_valences</span><span class="p">(</span><span class="n">structure</span><span class="p">)</span>
        <span class="n">el_val_dict</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span><span class="nb">zip</span><span class="p">(</span><span class="n">el</span><span class="p">,</span> <span class="n">valences</span><span class="p">))</span>

        <span class="n">gin</span> <span class="o">=</span> <span class="s2">&quot;species </span><span class="se">\n</span><span class="s2">&quot;</span>
        <span class="n">qerfstring</span> <span class="o">=</span> <span class="s2">&quot;qerfc</span><span class="se">\n</span><span class="s2">&quot;</span>

        <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">el_val_dict</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
            <span class="k">if</span> <span class="n">key</span> <span class="o">!=</span> <span class="s2">&quot;O&quot;</span> <span class="ow">and</span> <span class="n">el_val_dict</span><span class="p">[</span><span class="n">key</span><span class="p">]</span> <span class="o">%</span> <span class="mi">1</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">SystemError</span><span class="p">(</span><span class="s2">&quot;Oxide has mixed valence on metal&quot;</span><span class="p">)</span>
            <span class="n">specie_string</span> <span class="o">=</span> <span class="n">key</span> <span class="o">+</span> <span class="s2">&quot; core &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">el_val_dict</span><span class="p">[</span><span class="n">key</span><span class="p">])</span> <span class="o">+</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span>
            <span class="n">gin</span> <span class="o">+=</span> <span class="n">specie_string</span>
            <span class="n">qerfstring</span> <span class="o">+=</span> <span class="n">key</span> <span class="o">+</span> <span class="s2">&quot; &quot;</span> <span class="o">+</span> <span class="n">key</span> <span class="o">+</span> <span class="s2">&quot; 0.6000 10.0000 </span><span class="se">\n</span><span class="s2">&quot;</span>

        <span class="n">gin</span> <span class="o">+=</span> <span class="s2">&quot;# noelectrostatics </span><span class="se">\n</span><span class="s2"> Morse </span><span class="se">\n</span><span class="s2">&quot;</span>
        <span class="n">met_oxi_ters</span> <span class="o">=</span> <span class="n">TersoffPotential</span><span class="p">()</span><span class="o">.</span><span class="n">data</span>
        <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">el_val_dict</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
            <span class="k">if</span> <span class="n">key</span> <span class="o">!=</span> <span class="s2">&quot;O&quot;</span><span class="p">:</span>
                <span class="n">metal</span> <span class="o">=</span> <span class="n">key</span> <span class="o">+</span> <span class="s2">&quot;(&quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">el_val_dict</span><span class="p">[</span><span class="n">key</span><span class="p">]))</span> <span class="o">+</span> <span class="s2">&quot;)&quot;</span>
                <span class="n">ters_pot_str</span> <span class="o">=</span> <span class="n">met_oxi_ters</span><span class="p">[</span><span class="n">metal</span><span class="p">]</span>
                <span class="n">gin</span> <span class="o">+=</span> <span class="n">ters_pot_str</span>

        <span class="n">gin</span> <span class="o">+=</span> <span class="n">qerfstring</span>
        <span class="k">return</span> <span class="n">gin</span></div>

<div class="viewcode-block" id="GulpIO.get_energy"><a class="viewcode-back" href="../../../pymatgen.command_line.gulp_caller.html#pymatgen.command_line.gulp_caller.GulpIO.get_energy">[docs]</a>    <span class="k">def</span> <span class="nf">get_energy</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">gout</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            gout ():</span>

<span class="sd">        Returns:</span>
<span class="sd">            Energy</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">energy</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">gout</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">):</span>
            <span class="k">if</span> <span class="s2">&quot;Total lattice energy&quot;</span> <span class="ow">in</span> <span class="n">line</span> <span class="ow">and</span> <span class="s2">&quot;eV&quot;</span> <span class="ow">in</span> <span class="n">line</span><span class="p">:</span>
                <span class="n">energy</span> <span class="o">=</span> <span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
            <span class="k">elif</span> <span class="s2">&quot;Non-primitive unit cell&quot;</span> <span class="ow">in</span> <span class="n">line</span> <span class="ow">and</span> <span class="s2">&quot;eV&quot;</span> <span class="ow">in</span> <span class="n">line</span><span class="p">:</span>
                <span class="n">energy</span> <span class="o">=</span> <span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
        <span class="k">if</span> <span class="n">energy</span><span class="p">:</span>
            <span class="k">return</span> <span class="nb">float</span><span class="p">(</span><span class="n">energy</span><span class="p">[</span><span class="mi">4</span><span class="p">])</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="n">GulpError</span><span class="p">(</span><span class="s2">&quot;Energy not found in Gulp output&quot;</span><span class="p">)</span></div>

<div class="viewcode-block" id="GulpIO.get_relaxed_structure"><a class="viewcode-back" href="../../../pymatgen.command_line.gulp_caller.html#pymatgen.command_line.gulp_caller.GulpIO.get_relaxed_structure">[docs]</a>    <span class="k">def</span> <span class="nf">get_relaxed_structure</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">gout</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            gout ():</span>

<span class="sd">        Returns:</span>
<span class="sd">            (Structure) relaxed structure.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># Find the structure lines</span>
        <span class="n">structure_lines</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">cell_param_lines</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">output_lines</span> <span class="o">=</span> <span class="n">gout</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span>
        <span class="n">no_lines</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">output_lines</span><span class="p">)</span>
        <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="c1"># Compute the input lattice parameters</span>
        <span class="k">while</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">no_lines</span><span class="p">:</span>
            <span class="n">line</span> <span class="o">=</span> <span class="n">output_lines</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>
            <span class="k">if</span> <span class="s2">&quot;Full cell parameters&quot;</span> <span class="ow">in</span> <span class="n">line</span><span class="p">:</span>
                <span class="n">i</span> <span class="o">+=</span> <span class="mi">2</span>
                <span class="n">line</span> <span class="o">=</span> <span class="n">output_lines</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>
                <span class="n">a</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">8</span><span class="p">])</span>
                <span class="n">alpha</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">11</span><span class="p">])</span>
                <span class="n">line</span> <span class="o">=</span> <span class="n">output_lines</span><span class="p">[</span><span class="n">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">]</span>
                <span class="n">b</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">8</span><span class="p">])</span>
                <span class="n">beta</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">11</span><span class="p">])</span>
                <span class="n">line</span> <span class="o">=</span> <span class="n">output_lines</span><span class="p">[</span><span class="n">i</span> <span class="o">+</span> <span class="mi">2</span><span class="p">]</span>
                <span class="n">c</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">8</span><span class="p">])</span>
                <span class="n">gamma</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">11</span><span class="p">])</span>
                <span class="n">i</span> <span class="o">+=</span> <span class="mi">3</span>
                <span class="k">break</span>
            <span class="k">elif</span> <span class="s2">&quot;Cell parameters&quot;</span> <span class="ow">in</span> <span class="n">line</span><span class="p">:</span>
                <span class="n">i</span> <span class="o">+=</span> <span class="mi">2</span>
                <span class="n">line</span> <span class="o">=</span> <span class="n">output_lines</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>
                <span class="n">a</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">2</span><span class="p">])</span>
                <span class="n">alpha</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">5</span><span class="p">])</span>
                <span class="n">line</span> <span class="o">=</span> <span class="n">output_lines</span><span class="p">[</span><span class="n">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">]</span>
                <span class="n">b</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">2</span><span class="p">])</span>
                <span class="n">beta</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">5</span><span class="p">])</span>
                <span class="n">line</span> <span class="o">=</span> <span class="n">output_lines</span><span class="p">[</span><span class="n">i</span> <span class="o">+</span> <span class="mi">2</span><span class="p">]</span>
                <span class="n">c</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">2</span><span class="p">])</span>
                <span class="n">gamma</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">5</span><span class="p">])</span>
                <span class="n">i</span> <span class="o">+=</span> <span class="mi">3</span>
                <span class="k">break</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">i</span> <span class="o">+=</span> <span class="mi">1</span>

        <span class="k">while</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">no_lines</span><span class="p">:</span>
            <span class="n">line</span> <span class="o">=</span> <span class="n">output_lines</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>
            <span class="k">if</span> <span class="s2">&quot;Final fractional coordinates of atoms&quot;</span> <span class="ow">in</span> <span class="n">line</span><span class="p">:</span>
                <span class="c1"># read the site coordinates in the following lines</span>
                <span class="n">i</span> <span class="o">+=</span> <span class="mi">6</span>
                <span class="n">line</span> <span class="o">=</span> <span class="n">output_lines</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>
                <span class="k">while</span> <span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="mi">2</span><span class="p">]</span> <span class="o">!=</span> <span class="s1">&#39;--&#39;</span><span class="p">:</span>
                    <span class="n">structure_lines</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">line</span><span class="p">)</span>
                    <span class="n">i</span> <span class="o">+=</span> <span class="mi">1</span>
                    <span class="n">line</span> <span class="o">=</span> <span class="n">output_lines</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>
                    <span class="c1"># read the cell parameters</span>
                <span class="n">i</span> <span class="o">+=</span> <span class="mi">9</span>
                <span class="n">line</span> <span class="o">=</span> <span class="n">output_lines</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>
                <span class="k">if</span> <span class="s2">&quot;Final cell parameters&quot;</span> <span class="ow">in</span> <span class="n">line</span><span class="p">:</span>
                    <span class="n">i</span> <span class="o">+=</span> <span class="mi">3</span>
                    <span class="k">for</span> <span class="n">del_i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">6</span><span class="p">):</span>
                        <span class="n">line</span> <span class="o">=</span> <span class="n">output_lines</span><span class="p">[</span><span class="n">i</span> <span class="o">+</span> <span class="n">del_i</span><span class="p">]</span>
                        <span class="n">cell_param_lines</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">line</span><span class="p">)</span>

                <span class="k">break</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">i</span> <span class="o">+=</span> <span class="mi">1</span>

        <span class="c1"># Process the structure lines</span>
        <span class="k">if</span> <span class="n">structure_lines</span><span class="p">:</span>
            <span class="n">sp</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="n">coords</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">structure_lines</span><span class="p">:</span>
                <span class="n">fields</span> <span class="o">=</span> <span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
                <span class="k">if</span> <span class="n">fields</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;c&#39;</span><span class="p">:</span>
                    <span class="n">sp</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">fields</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
                    <span class="n">coords</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="nb">float</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">fields</span><span class="p">[</span><span class="mi">3</span><span class="p">:</span><span class="mi">6</span><span class="p">]))</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">IOError</span><span class="p">(</span><span class="s2">&quot;No structure found&quot;</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">cell_param_lines</span><span class="p">:</span>
            <span class="n">a</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">cell_param_lines</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">1</span><span class="p">])</span>
            <span class="n">b</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">cell_param_lines</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">1</span><span class="p">])</span>
            <span class="n">c</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">cell_param_lines</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">1</span><span class="p">])</span>
            <span class="n">alpha</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">cell_param_lines</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">1</span><span class="p">])</span>
            <span class="n">beta</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">cell_param_lines</span><span class="p">[</span><span class="mi">4</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">1</span><span class="p">])</span>
            <span class="n">gamma</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">cell_param_lines</span><span class="p">[</span><span class="mi">5</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">1</span><span class="p">])</span>
        <span class="n">latt</span> <span class="o">=</span> <span class="n">Lattice</span><span class="o">.</span><span class="n">from_parameters</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">alpha</span><span class="p">,</span> <span class="n">beta</span><span class="p">,</span> <span class="n">gamma</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">Structure</span><span class="p">(</span><span class="n">latt</span><span class="p">,</span> <span class="n">sp</span><span class="p">,</span> <span class="n">coords</span><span class="p">)</span></div></div>


<div class="viewcode-block" id="GulpCaller"><a class="viewcode-back" href="../../../pymatgen.command_line.gulp_caller.html#pymatgen.command_line.gulp_caller.GulpCaller">[docs]</a><span class="k">class</span> <span class="nc">GulpCaller</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Class to run gulp from commandline</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">cmd</span><span class="o">=</span><span class="s1">&#39;gulp&#39;</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Initialize with the executable if not in the standard path</span>

<span class="sd">        Args:</span>
<span class="sd">            cmd: Command. Defaults to gulp.</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">def</span> <span class="nf">is_exe</span><span class="p">(</span><span class="n">f</span><span class="p">):</span>
            <span class="k">return</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">isfile</span><span class="p">(</span><span class="n">f</span><span class="p">)</span> <span class="ow">and</span> <span class="n">os</span><span class="o">.</span><span class="n">access</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">os</span><span class="o">.</span><span class="n">X_OK</span><span class="p">)</span>

        <span class="n">fpath</span><span class="p">,</span> <span class="n">fname</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="n">cmd</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">fpath</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">is_exe</span><span class="p">(</span><span class="n">cmd</span><span class="p">):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_gulp_cmd</span> <span class="o">=</span> <span class="n">cmd</span>
                <span class="k">return</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">path</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s1">&#39;PATH&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">pathsep</span><span class="p">):</span>
                <span class="n">path</span> <span class="o">=</span> <span class="n">path</span><span class="o">.</span><span class="n">strip</span><span class="p">(</span><span class="s1">&#39;&quot;&#39;</span><span class="p">)</span>
                <span class="n">file</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="n">cmd</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">is_exe</span><span class="p">(</span><span class="n">file</span><span class="p">):</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">_gulp_cmd</span> <span class="o">=</span> <span class="n">file</span>
                    <span class="k">return</span>
        <span class="k">raise</span> <span class="n">GulpError</span><span class="p">(</span><span class="s2">&quot;Executable not found&quot;</span><span class="p">)</span>

<div class="viewcode-block" id="GulpCaller.run"><a class="viewcode-back" href="../../../pymatgen.command_line.gulp_caller.html#pymatgen.command_line.gulp_caller.GulpCaller.run">[docs]</a>    <span class="k">def</span> <span class="nf">run</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">gin</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Run GULP using the gin as input</span>

<span class="sd">        Args:</span>
<span class="sd">            gin: GULP input string</span>

<span class="sd">        Returns:</span>
<span class="sd">            gout: GULP output string</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">with</span> <span class="n">ScratchDir</span><span class="p">(</span><span class="s2">&quot;.&quot;</span><span class="p">):</span>
            <span class="n">p</span> <span class="o">=</span> <span class="n">subprocess</span><span class="o">.</span><span class="n">Popen</span><span class="p">(</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_gulp_cmd</span><span class="p">,</span> <span class="n">stdout</span><span class="o">=</span><span class="n">subprocess</span><span class="o">.</span><span class="n">PIPE</span><span class="p">,</span>
                <span class="n">stdin</span><span class="o">=</span><span class="n">subprocess</span><span class="o">.</span><span class="n">PIPE</span><span class="p">,</span> <span class="n">stderr</span><span class="o">=</span><span class="n">subprocess</span><span class="o">.</span><span class="n">PIPE</span>
            <span class="p">)</span>

            <span class="n">out</span><span class="p">,</span> <span class="n">err</span> <span class="o">=</span> <span class="n">p</span><span class="o">.</span><span class="n">communicate</span><span class="p">(</span><span class="nb">bytearray</span><span class="p">(</span><span class="n">gin</span><span class="p">,</span> <span class="s2">&quot;utf-8&quot;</span><span class="p">))</span>
            <span class="n">out</span> <span class="o">=</span> <span class="n">out</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="s2">&quot;utf-8&quot;</span><span class="p">)</span>
            <span class="n">err</span> <span class="o">=</span> <span class="n">err</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="s2">&quot;utf-8&quot;</span><span class="p">)</span>

            <span class="k">if</span> <span class="s2">&quot;Error&quot;</span> <span class="ow">in</span> <span class="n">err</span> <span class="ow">or</span> <span class="s2">&quot;error&quot;</span> <span class="ow">in</span> <span class="n">err</span><span class="p">:</span>
                <span class="nb">print</span><span class="p">(</span><span class="n">gin</span><span class="p">)</span>
                <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;----output_0---------&quot;</span><span class="p">)</span>
                <span class="nb">print</span><span class="p">(</span><span class="n">out</span><span class="p">)</span>
                <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;----End of output_0------</span><span class="se">\n\n\n</span><span class="s2">&quot;</span><span class="p">)</span>
                <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;----output_1--------&quot;</span><span class="p">)</span>
                <span class="nb">print</span><span class="p">(</span><span class="n">out</span><span class="p">)</span>
                <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;----End of output_1------&quot;</span><span class="p">)</span>
                <span class="k">raise</span> <span class="n">GulpError</span><span class="p">(</span><span class="n">err</span><span class="p">)</span>

            <span class="c1"># We may not need this</span>
            <span class="k">if</span> <span class="s2">&quot;ERROR&quot;</span> <span class="ow">in</span> <span class="n">out</span><span class="p">:</span>
                <span class="k">raise</span> <span class="n">GulpError</span><span class="p">(</span><span class="n">out</span><span class="p">)</span>

            <span class="c1"># Sometimes optimisation may fail to reach convergence</span>
            <span class="n">conv_err_string</span> <span class="o">=</span> <span class="s2">&quot;Conditions for a minimum have not been satisfied&quot;</span>
            <span class="k">if</span> <span class="n">conv_err_string</span> <span class="ow">in</span> <span class="n">out</span><span class="p">:</span>
                <span class="k">raise</span> <span class="n">GulpConvergenceError</span><span class="p">()</span>

            <span class="n">gout</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
            <span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">out</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">):</span>
                <span class="n">gout</span> <span class="o">=</span> <span class="n">gout</span> <span class="o">+</span> <span class="n">line</span> <span class="o">+</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span>
            <span class="k">return</span> <span class="n">gout</span></div></div>


<div class="viewcode-block" id="get_energy_tersoff"><a class="viewcode-back" href="../../../pymatgen.command_line.gulp_caller.html#pymatgen.command_line.gulp_caller.get_energy_tersoff">[docs]</a><span class="k">def</span> <span class="nf">get_energy_tersoff</span><span class="p">(</span><span class="n">structure</span><span class="p">,</span> <span class="n">gulp_cmd</span><span class="o">=</span><span class="s1">&#39;gulp&#39;</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Compute the energy of a structure using Tersoff potential.</span>

<span class="sd">    Args:</span>
<span class="sd">        structure: pymatgen.core.structure.Structure</span>
<span class="sd">        gulp_cmd: GULP command if not in standard place</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">gio</span> <span class="o">=</span> <span class="n">GulpIO</span><span class="p">()</span>
    <span class="n">gc</span> <span class="o">=</span> <span class="n">GulpCaller</span><span class="p">(</span><span class="n">gulp_cmd</span><span class="p">)</span>
    <span class="n">gin</span> <span class="o">=</span> <span class="n">gio</span><span class="o">.</span><span class="n">tersoff_input</span><span class="p">(</span><span class="n">structure</span><span class="p">)</span>
    <span class="n">gout</span> <span class="o">=</span> <span class="n">gc</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="n">gin</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">gio</span><span class="o">.</span><span class="n">get_energy</span><span class="p">(</span><span class="n">gout</span><span class="p">)</span></div>


<div class="viewcode-block" id="get_energy_buckingham"><a class="viewcode-back" href="../../../pymatgen.command_line.gulp_caller.html#pymatgen.command_line.gulp_caller.get_energy_buckingham">[docs]</a><span class="k">def</span> <span class="nf">get_energy_buckingham</span><span class="p">(</span><span class="n">structure</span><span class="p">,</span> <span class="n">gulp_cmd</span><span class="o">=</span><span class="s1">&#39;gulp&#39;</span><span class="p">,</span>
                          <span class="n">keywords</span><span class="o">=</span><span class="p">(</span><span class="s1">&#39;optimise&#39;</span><span class="p">,</span> <span class="s1">&#39;conp&#39;</span><span class="p">,</span> <span class="s1">&#39;qok&#39;</span><span class="p">),</span>
                          <span class="n">valence_dict</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Compute the energy of a structure using Buckingham potential.</span>

<span class="sd">    Args:</span>
<span class="sd">        structure: pymatgen.core.structure.Structure</span>
<span class="sd">        gulp_cmd: GULP command if not in standard place</span>
<span class="sd">        keywords: GULP first line keywords</span>
<span class="sd">        valence_dict: {El: valence}. Needed if the structure is not charge</span>
<span class="sd">            neutral.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">gio</span> <span class="o">=</span> <span class="n">GulpIO</span><span class="p">()</span>
    <span class="n">gc</span> <span class="o">=</span> <span class="n">GulpCaller</span><span class="p">(</span><span class="n">gulp_cmd</span><span class="p">)</span>
    <span class="n">gin</span> <span class="o">=</span> <span class="n">gio</span><span class="o">.</span><span class="n">buckingham_input</span><span class="p">(</span>
        <span class="n">structure</span><span class="p">,</span> <span class="n">keywords</span><span class="p">,</span> <span class="n">valence_dict</span><span class="o">=</span><span class="n">valence_dict</span>
    <span class="p">)</span>
    <span class="n">gout</span> <span class="o">=</span> <span class="n">gc</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="n">gin</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">gio</span><span class="o">.</span><span class="n">get_energy</span><span class="p">(</span><span class="n">gout</span><span class="p">)</span></div>


<div class="viewcode-block" id="get_energy_relax_structure_buckingham"><a class="viewcode-back" href="../../../pymatgen.command_line.gulp_caller.html#pymatgen.command_line.gulp_caller.get_energy_relax_structure_buckingham">[docs]</a><span class="k">def</span> <span class="nf">get_energy_relax_structure_buckingham</span><span class="p">(</span><span class="n">structure</span><span class="p">,</span>
                                          <span class="n">gulp_cmd</span><span class="o">=</span><span class="s1">&#39;gulp&#39;</span><span class="p">,</span>
                                          <span class="n">keywords</span><span class="o">=</span><span class="p">(</span><span class="s1">&#39;optimise&#39;</span><span class="p">,</span> <span class="s1">&#39;conp&#39;</span><span class="p">),</span>
                                          <span class="n">valence_dict</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Relax a structure and compute the energy using Buckingham potential.</span>

<span class="sd">    Args:</span>
<span class="sd">        structure: pymatgen.core.structure.Structure</span>
<span class="sd">        gulp_cmd: GULP command if not in standard place</span>
<span class="sd">        keywords: GULP first line keywords</span>
<span class="sd">        valence_dict: {El: valence}. Needed if the structure is not charge</span>
<span class="sd">            neutral.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">gio</span> <span class="o">=</span> <span class="n">GulpIO</span><span class="p">()</span>
    <span class="n">gc</span> <span class="o">=</span> <span class="n">GulpCaller</span><span class="p">(</span><span class="n">gulp_cmd</span><span class="p">)</span>
    <span class="n">gin</span> <span class="o">=</span> <span class="n">gio</span><span class="o">.</span><span class="n">buckingham_input</span><span class="p">(</span>
        <span class="n">structure</span><span class="p">,</span> <span class="n">keywords</span><span class="p">,</span> <span class="n">valence_dict</span><span class="o">=</span><span class="n">valence_dict</span>
    <span class="p">)</span>
    <span class="n">gout</span> <span class="o">=</span> <span class="n">gc</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="n">gin</span><span class="p">)</span>
    <span class="n">energy</span> <span class="o">=</span> <span class="n">gio</span><span class="o">.</span><span class="n">get_energy</span><span class="p">(</span><span class="n">gout</span><span class="p">)</span>
    <span class="n">relax_structure</span> <span class="o">=</span> <span class="n">gio</span><span class="o">.</span><span class="n">get_relaxed_structure</span><span class="p">(</span><span class="n">gout</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">energy</span><span class="p">,</span> <span class="n">relax_structure</span></div>


<div class="viewcode-block" id="GulpError"><a class="viewcode-back" href="../../../pymatgen.command_line.gulp_caller.html#pymatgen.command_line.gulp_caller.GulpError">[docs]</a><span class="k">class</span> <span class="nc">GulpError</span><span class="p">(</span><span class="ne">Exception</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Exception class for GULP.</span>
<span class="sd">    Raised when the GULP gives an error</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">msg</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            msg (str): Message</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">msg</span> <span class="o">=</span> <span class="n">msg</span>

    <span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="s2">&quot;GulpError : &quot;</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">msg</span></div>


<div class="viewcode-block" id="GulpConvergenceError"><a class="viewcode-back" href="../../../pymatgen.command_line.gulp_caller.html#pymatgen.command_line.gulp_caller.GulpConvergenceError">[docs]</a><span class="k">class</span> <span class="nc">GulpConvergenceError</span><span class="p">(</span><span class="ne">Exception</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Exception class for GULP.</span>
<span class="sd">    Raised when proper convergence is not reached in Mott-Littleton</span>
<span class="sd">    defect energy optimisation procedure in GULP</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">msg</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            msg (str): Message</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">msg</span> <span class="o">=</span> <span class="n">msg</span>

    <span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">msg</span></div>


<div class="viewcode-block" id="BuckinghamPotential"><a class="viewcode-back" href="../../../pymatgen.command_line.gulp_caller.html#pymatgen.command_line.gulp_caller.BuckinghamPotential">[docs]</a><span class="k">class</span> <span class="nc">BuckinghamPotential</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Generate the Buckingham Potential Table from the bush.lib and lewis.lib.</span>

<span class="sd">    Ref:</span>
<span class="sd">    T.S.Bush, J.D.Gale, C.R.A.Catlow and P.D. Battle,  J. Mater Chem.,</span>
<span class="sd">    4, 831-837 (1994).</span>
<span class="sd">    G.V. Lewis and C.R.A. Catlow, J. Phys. C: Solid State Phys., 18,</span>
<span class="sd">    1149-1161 (1985)</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">bush_lewis_flag</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            bush_lewis_flag (str): Flag for using Bush or Lewis potential.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">assert</span> <span class="n">bush_lewis_flag</span> <span class="ow">in</span> <span class="p">{</span><span class="s1">&#39;bush&#39;</span><span class="p">,</span> <span class="s1">&#39;lewis&#39;</span><span class="p">}</span>
        <span class="n">pot_file</span> <span class="o">=</span> <span class="s2">&quot;bush.lib&quot;</span> <span class="k">if</span> <span class="n">bush_lewis_flag</span> <span class="o">==</span> <span class="s2">&quot;bush&quot;</span> <span class="k">else</span> <span class="s2">&quot;lewis.lib&quot;</span>
        <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s2">&quot;GULP_LIB&quot;</span><span class="p">],</span> <span class="n">pot_file</span><span class="p">),</span> <span class="s1">&#39;rt&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
            <span class="c1"># In lewis.lib there is no shell for cation</span>
            <span class="n">species_dict</span><span class="p">,</span> <span class="n">pot_dict</span><span class="p">,</span> <span class="n">spring_dict</span> <span class="o">=</span> <span class="p">{},</span> <span class="p">{},</span> <span class="p">{}</span>
            <span class="n">sp_flg</span><span class="p">,</span> <span class="n">pot_flg</span><span class="p">,</span> <span class="n">spring_flg</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span> <span class="kc">False</span><span class="p">,</span> <span class="kc">False</span>
            <span class="k">for</span> <span class="n">row</span> <span class="ow">in</span> <span class="n">f</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">row</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s2">&quot;#&quot;</span><span class="p">:</span>
                    <span class="k">continue</span>
                <span class="k">if</span> <span class="n">row</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s2">&quot;species&quot;</span><span class="p">:</span>
                    <span class="n">sp_flg</span><span class="p">,</span> <span class="n">pot_flg</span><span class="p">,</span> <span class="n">spring_flg</span> <span class="o">=</span> <span class="kc">True</span><span class="p">,</span> <span class="kc">False</span><span class="p">,</span> <span class="kc">False</span>
                    <span class="k">continue</span>
                <span class="k">if</span> <span class="n">row</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s2">&quot;buckingham&quot;</span><span class="p">:</span>
                    <span class="n">sp_flg</span><span class="p">,</span> <span class="n">pot_flg</span><span class="p">,</span> <span class="n">spring_flg</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span> <span class="kc">True</span><span class="p">,</span> <span class="kc">False</span>
                    <span class="k">continue</span>
                <span class="k">if</span> <span class="n">row</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s2">&quot;spring&quot;</span><span class="p">:</span>
                    <span class="n">sp_flg</span><span class="p">,</span> <span class="n">pot_flg</span><span class="p">,</span> <span class="n">spring_flg</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span> <span class="kc">False</span><span class="p">,</span> <span class="kc">True</span>
                    <span class="k">continue</span>

                <span class="n">elmnt</span> <span class="o">=</span> <span class="n">row</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">0</span><span class="p">]</span>
                <span class="k">if</span> <span class="n">sp_flg</span><span class="p">:</span>
                    <span class="k">if</span> <span class="n">bush_lewis_flag</span> <span class="o">==</span> <span class="s2">&quot;bush&quot;</span><span class="p">:</span>
                        <span class="k">if</span> <span class="n">elmnt</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">species_dict</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
                            <span class="n">species_dict</span><span class="p">[</span><span class="n">elmnt</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;inp_str&#39;</span><span class="p">:</span> <span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="s1">&#39;oxi&#39;</span><span class="p">:</span> <span class="mi">0</span><span class="p">}</span>
                        <span class="n">species_dict</span><span class="p">[</span><span class="n">elmnt</span><span class="p">][</span><span class="s1">&#39;inp_str&#39;</span><span class="p">]</span> <span class="o">+=</span> <span class="n">row</span>
                        <span class="n">species_dict</span><span class="p">[</span><span class="n">elmnt</span><span class="p">][</span><span class="s1">&#39;oxi&#39;</span><span class="p">]</span> <span class="o">+=</span> <span class="nb">float</span><span class="p">(</span><span class="n">row</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">2</span><span class="p">])</span>
                    <span class="k">elif</span> <span class="n">bush_lewis_flag</span> <span class="o">==</span> <span class="s2">&quot;lewis&quot;</span><span class="p">:</span>
                        <span class="k">if</span> <span class="n">elmnt</span> <span class="o">==</span> <span class="s2">&quot;O&quot;</span><span class="p">:</span>
                            <span class="k">if</span> <span class="n">row</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="s2">&quot;core&quot;</span><span class="p">:</span>
                                <span class="n">species_dict</span><span class="p">[</span><span class="s2">&quot;O_core&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">row</span>
                            <span class="k">if</span> <span class="n">row</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="s2">&quot;shel&quot;</span><span class="p">:</span>
                                <span class="n">species_dict</span><span class="p">[</span><span class="s2">&quot;O_shel&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">row</span>
                        <span class="k">else</span><span class="p">:</span>
                            <span class="n">metal</span> <span class="o">=</span> <span class="n">elmnt</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;_&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
                            <span class="c1"># oxi_state = metaloxi.split(&#39;_&#39;)[1][0]</span>
                            <span class="n">species_dict</span><span class="p">[</span><span class="n">elmnt</span><span class="p">]</span> <span class="o">=</span> <span class="n">metal</span> <span class="o">+</span> <span class="s2">&quot; core &quot;</span> <span class="o">+</span> <span class="n">row</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">2</span><span class="p">]</span> <span class="o">+</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span>
                    <span class="k">continue</span>

                <span class="k">if</span> <span class="n">pot_flg</span><span class="p">:</span>
                    <span class="k">if</span> <span class="n">bush_lewis_flag</span> <span class="o">==</span> <span class="s2">&quot;bush&quot;</span><span class="p">:</span>
                        <span class="n">pot_dict</span><span class="p">[</span><span class="n">elmnt</span><span class="p">]</span> <span class="o">=</span> <span class="n">row</span>
                    <span class="k">elif</span> <span class="n">bush_lewis_flag</span> <span class="o">==</span> <span class="s2">&quot;lewis&quot;</span><span class="p">:</span>
                        <span class="k">if</span> <span class="n">elmnt</span> <span class="o">==</span> <span class="s2">&quot;O&quot;</span><span class="p">:</span>
                            <span class="n">pot_dict</span><span class="p">[</span><span class="s2">&quot;O&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">row</span>
                        <span class="k">else</span><span class="p">:</span>
                            <span class="n">metal</span> <span class="o">=</span> <span class="n">elmnt</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;_&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
                            <span class="c1"># oxi_state = metaloxi.split(&#39;_&#39;)[1][0]</span>
                            <span class="n">pot_dict</span><span class="p">[</span><span class="n">elmnt</span><span class="p">]</span> <span class="o">=</span> <span class="n">metal</span> <span class="o">+</span> <span class="s2">&quot; &quot;</span> <span class="o">+</span> <span class="s2">&quot; &quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span>
                                <span class="n">row</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">1</span><span class="p">:])</span> <span class="o">+</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span>
                    <span class="k">continue</span>

                <span class="k">if</span> <span class="n">spring_flg</span><span class="p">:</span>
                    <span class="n">spring_dict</span><span class="p">[</span><span class="n">elmnt</span><span class="p">]</span> <span class="o">=</span> <span class="n">row</span>

            <span class="k">if</span> <span class="n">bush_lewis_flag</span> <span class="o">==</span> <span class="s2">&quot;bush&quot;</span><span class="p">:</span>
                <span class="c1"># Fill the null keys in spring dict with empty strings</span>
                <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">pot_dict</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
                    <span class="k">if</span> <span class="n">key</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">spring_dict</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
                        <span class="n">spring_dict</span><span class="p">[</span><span class="n">key</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">species_dict</span> <span class="o">=</span> <span class="n">species_dict</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">pot_dict</span> <span class="o">=</span> <span class="n">pot_dict</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">spring_dict</span> <span class="o">=</span> <span class="n">spring_dict</span></div>


<div class="viewcode-block" id="TersoffPotential"><a class="viewcode-back" href="../../../pymatgen.command_line.gulp_caller.html#pymatgen.command_line.gulp_caller.TersoffPotential">[docs]</a><span class="k">class</span> <span class="nc">TersoffPotential</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Generate Tersoff Potential Table from &quot;OxideTersoffPotentialentials&quot; file</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Init TersoffPotential</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">module_dir</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">dirname</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">abspath</span><span class="p">(</span><span class="vm">__file__</span><span class="p">))</span>
        <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">module_dir</span><span class="p">,</span> <span class="s2">&quot;OxideTersoffPotentials&quot;</span><span class="p">),</span> <span class="s2">&quot;r&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
            <span class="n">data</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">()</span>
            <span class="k">for</span> <span class="n">row</span> <span class="ow">in</span> <span class="n">f</span><span class="p">:</span>
                <span class="n">metaloxi</span> <span class="o">=</span> <span class="n">row</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">0</span><span class="p">]</span>
                <span class="n">line</span> <span class="o">=</span> <span class="n">row</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;)&quot;</span><span class="p">)</span>
                <span class="n">data</span><span class="p">[</span><span class="n">metaloxi</span><span class="p">]</span> <span class="o">=</span> <span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="n">data</span></div>
</pre></div>

            <div class="clearer"></div>
          </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../index.html">pymatgen 2020.7.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../pymatgen.html" >pymatgen</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">pymatgen.command_line.gulp_caller</a></li> 
      </ul>
    </div>

    <div class="footer" role="contentinfo">
        &#169; Copyright 2011, Pymatgen Development Team.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
    </div>
<div class="footer">This page uses <a href="http://analytics.google.com/">
Google Analytics</a> to collect statistics. You can disable it by blocking
the JavaScript coming from www.google-analytics.com.
<script type="text/javascript">
  (function() {
    var ga = document.createElement('script');
    ga.src = ('https:' == document.location.protocol ?
              'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    ga.setAttribute('async', 'true');
    document.documentElement.firstChild.appendChild(ga);
  })();
</script>
</div>

  </body>
</html>